package cn.chenfeifx.checker.util;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DateUtil {
    public static boolean checkDate(String dateString) {
        if (dateString.equals("000000")) {
            return true;
        }
        if (dateString.endsWith("00")) {
            return true;
        }
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");
        try {
            LocalDate.parse(dateString, dtf);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public static boolean checkYear(String yearString) {
        String regex = "^[0-9]{4}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(yearString);
        return matcher.matches();
    }
}
